Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

468
Vistas
AssertionError [ERR_ASSERTION]: you must pass Joi as an argument

How do I solve this Joi problem(Using express, joi@17.4.2,joi-objectid@2.0.0, ,mongoose) I am trying to link two mongoose schemas using ref as

{
...
   enroledcourses: [{
        type: Schema.Types.ObjectId,
        ref: "courses"
    }]
}

joi validation

...    
enroledcourses: Joi.array().items(Joi.ObjectId()).required()

the course collection is fine i have imported it at index.js as below

const Joi = require("joi")
Joi.objectId = require("joi-objectid")(Joi);

but i end up getting this error enter image description here

AssertionError [ERR_ASSERTION]: you must pass Joi as an argument at joiObjectId (D:\Programing projects\2021\ikodeafrika\ikodeafrikabackend\node_modules\joi-objectid\index.js:6:3) at Object. (D:\Programing projects\2021\ikodeafrika\ikodeafrikabackend\index.js:2:39)

index.js:2:39 being the joi.objectId import above plus i'm getting this when i hover over the joi.objectId import statement

Property 'objectId' may not exist on type 'Root'. Did you mean 'object'?ts(2568) index.d.ts(1998, 9): 'object' is declared here. any

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is because joi-objectid@2.0.0 is not compatible with joi@17.4.2.

Fix:
Upgrade joi-objectid to v4.0.2

About the Typescript error (Property 'objectId' may not exist on type 'Root'), you need to augment the type of Joi to add the objectId property. This can be done by creating a declaration file:

// src/types/joi.d.ts
import { Schema } from "joi";

declare module "joi" {
  interface Root {
    objectId(): Schema;
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda